package com.gwsdk.paysdk.acitvityV2.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.gwsdk.paysdk.utils.GWInflaterUtils;


public class GWPreviewImageDialog extends DialogFragment {


    private Context context;
    private String url;
    private ImageView imageView;
    public GWPreviewImageDialog() {

    }

    @SuppressLint("ValidFragment")
    public GWPreviewImageDialog(Context context, String url){
        this.context = context;
        this.url = url;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(GWInflaterUtils.getLayout(context,"gw_dialog_preview_image"), container, false);
        imageView = view.findViewById(GWInflaterUtils.getControl(context,"image"));
        Glide.with(context).load(url).into(imageView);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏(主要功能就是去除页面弹出时顶部黑色条)
        // 设置对话框的样式
        setStyle(STYLE_NO_FRAME, GWInflaterUtils.getIdByName(context,"style","gw_preview_dialog"));
    }

    public void show(FragmentManager fm){
        if (fm == null) {
            return;
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(this, "GWPreviewImageDialog");
        ft.show(this);
        ft.commitAllowingStateLoss();
    }
}
